package com.blog.frontend.pages;

import java.util.ArrayList;
import java.util.Collection;

import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;

import com.blog.frontend.pages.parts.ArticlePreViewer;
import com.blog.jdo.ArticleDAO;
import com.blog.model.Article;

public class ListArticlesPage extends AbstractPage {
	
	public static final String ARTICLE_ID = "articleId";
	public static final String ARTICLE_MODE = "articleMode";
	public static final String ARTICLE_MODE_EDIT = "edit";
	
	public ListArticlesPage() {
		
		final ArticleDAO articleDAO = new ArticleDAO();
		final Collection<Article> articles = articleDAO.getArticles();
		
		final ListView articleListView = new ListView("articles", new ArrayList<Article>(articles)) {
			private static final long serialVersionUID = -1954357564994001575L;
			
			@Override
			protected void populateItem(final ListItem arg0) {
				final ArticlePreViewer articleContainer = new ArticlePreViewer("element");
				arg0.add(articleContainer);
				articleContainer.setArticle((Article) arg0.getModelObject());
			}
		};
		
		add(articleListView);
		
	}
	
}
